package com.project.service.impl;

import com.project.bean.FacilityBean;
import com.project.dao.IFacilityDao;
import com.project.dao.IRoomDao;
import com.project.service.IFacilityService;
import com.project.service.IRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FacilityServiceImpl implements IFacilityService {
    @Autowired
    private IFacilityDao facilityDao;
    @Autowired
    private IRoomDao roomDao;

    @Override
    public void update(Integer facilityId, Integer roomId) {
        facilityDao.updateStatus(facilityId, "已解决");
        int facilityNum = facilityDao.findFacilitiesNum(roomId, "未解决");
        if (facilityNum==0){
            roomDao.updateRoomStatus(roomId,"正常");
        }
    }

    @Override
    public void add(FacilityBean facility) {
        facilityDao.add(facility);
        roomDao.updateRoomStatus(facility.getRoomBean().getId(), "设施损坏");
    }

    @Override
    public List<FacilityBean> findByRoomId(int roomId) {
        return facilityDao.findByRoomId(roomId);
    }
}
